package ru.spb.osll.myfit.common;

import com.google.gwt.user.client.rpc.IsSerializable;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Vassar
 * Date: 04.03.2011
 * Time: 12:33:29
 * To change this template use File | Settings | File Templates.
 */
public class TreeNode implements Serializable, IsSerializable {
    private static final long serialVersionUID = 3L;
    private ArrayList<TreeNode> children = null;
    private String reference;

    /**
     * cTtor
     *
     * @param obj referenced object
     */
    public TreeNode(String obj) {
        this.reference = obj;
    }

    public TreeNode() {
    }

    public void hasChild() {
        if (children == null) children = new ArrayList<TreeNode>();
    }

    /**
     * add child node
     *
     * @param child node to be added
     */
    public void addChildNode(TreeNode child) {
        hasChild();
        if (!children.contains(child))
            children.add(child);
    }

    /**
     * @return List of children
     */
    public List<TreeNode> getChildren() {
        return children;
    }

    /**
     * @return reference object
     */
    public String getReference() {
        return reference;
    }
}
